package com.lq.educationsystem.examination.service.impl;

import com.lq.educationsystem.common.util.*;
import com.lq.educationsystem.common.vo.StudentExaminationPageVo;
import com.lq.educationsystem.examination.entiy.StudentExaminationTb;
import com.lq.educationsystem.examination.mapper.StudentExaminationTbMapper;
import com.lq.educationsystem.examination.service.ExaminationStudentBaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExaminationStudentBaseImpl implements ExaminationStudentBaseService {

    @Autowired
    StudentExaminationTbMapper studentExaminationTbMapper;

    @Override
    public void insertInfo(StudentExaminationTb studentExaminationInfo) {
        int row = studentExaminationTbMapper.insert(studentExaminationInfo);

        System.out.println("ExaminationStudent插入数据影响行数为:" +row);
    }

    @Override
    public void deleteById(Integer studentExaminationId) {
        int row = studentExaminationTbMapper.deleteByPrimaryKey(Long.valueOf(studentExaminationId));

        System.out.println("ExaminationStudent删除数据影响行数为:"+row);
    }

    @Override
    public void updateInfo(StudentExaminationTb studentExaminationInfo) {
        int row = studentExaminationTbMapper.updateByPrimaryKeySelective(studentExaminationInfo);

        System.out.println("ExaminationStudent更新数据影响行数为:"+row);
    }

    @Override
    public Result queryById(Integer studentExaminationId) {

        StudentExaminationTb studentExaminationInfo = studentExaminationTbMapper.selectByPrimaryKey(Long.valueOf(studentExaminationId));
        return ResultBuild.buildOk(new Result<StudentExaminationTb>(),studentExaminationInfo);
    }

    @Override
    public ResultPage<StudentExaminationTb> queryList(StudentExaminationPageVo studentExaminationPageVo) {
        //获取页数
        Integer page = studentExaminationPageVo.getPage();
        Integer pageSize = studentExaminationPageVo.getPageSize();
        int start = PageUtil.getStart(page, pageSize);

        //数据拷贝
        StudentExaminationTb studentExaminationTb = new StudentExaminationTb();
        BeanUtils.copyProperties(studentExaminationPageVo,studentExaminationTb);

        //查询
        List<StudentExaminationTb> studentExaminationTbs = studentExaminationTbMapper.queryList(start,pageSize,studentExaminationTb);
        System.out.println("输出的结果是:"+studentExaminationTbs);

        int counts=0;

        counts =studentExaminationTbMapper.queryCount(studentExaminationTb);

        return ResultPageBuild.pageBuildOk(new ResultPage<StudentExaminationTb>(),page,pageSize,counts,studentExaminationTbs);

    }

    @Override
    public ResultPage<StudentExaminationTb> queryStudentExaminationInfoByStudentIdAndExaminationId(List<Integer> examinationIdList, Integer studentId) {
        //考试id
        List<StudentExaminationTb> studentExaminationTbList =studentExaminationTbMapper.queryStudentExaminationInfoByStudentIdAndExaminationId(examinationIdList,studentId);

        //查询考试信息


        ResultPage<StudentExaminationTb> studentExaminationTbResultPage = new ResultPage<>();

        studentExaminationTbResultPage.setData(studentExaminationTbList);
        return studentExaminationTbResultPage;
    }

    /**+
     * 批量插入班级该课程考试信息
     * @param studentIdInfoList
     * @param examinationId
     * @return
     */
    @Override
    public Result addBatchStudentExaminationInfoByExaminationIdAndStudentId(List<Integer> studentIdInfoList, Integer examinationId) {
        Integer row =  studentExaminationTbMapper.addBatchStudentExaminationInfoByExaminationIdAndStudentId(studentIdInfoList,examinationId);
        if (row > 0) {
            //成功
            return ResultBuild.buildOk(row);
        }else {
            //失败
            return ResultBuild.buildDefeat();
        }


    }
    //插入数据

}
